package com.java复习.jdbc.游戏.demo3;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao extends BaseDao{



    public User login(String account,String password){
        Connection connection = getConnection();
        User user = null;
        PreparedStatement preparedStatement = null;
        ResultSet rs = null;
        try {
            preparedStatement = connection.prepareStatement("select * from user where account=? and password=?");
            preparedStatement.setString(1,account);
            preparedStatement.setString(2,password);
            rs  = preparedStatement.executeQuery();
            while(rs.next()){
                user = new User(rs.getInt(1),
                        rs.getString(2),
                        null,null,
                        rs.getInt(5),
                        rs.getInt(6),
                        rs.getInt(7),
                        rs.getInt(8),rs.getInt(9));
            }
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }finally {
            close(connection,preparedStatement,rs);
        }

        return user;
    }
}
